package com.example.cd5160866.urlapp;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.cd5160866.urlapp.view.ShadowView;
import com.example.cd5160866.urlapp.view.ViewReplaceHelper;


public class Demo7SimpleActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        new ViewReplaceHelper.Builder(this)
                .orBackGround(R.drawable.bg_btn_dangers, R.drawable.bg_btn_primary)
                .withTargetViewClass(TextView.class, LinearLayout.class,RelativeLayout.class,FrameLayout.class)
                .build()
                .replace(new ViewReplaceHelper.BackGroundConverter() {
                    @Override
                    public View onChangePrinceWithBackGround(Context context, String viewName, AttributeSet princeAttrs, @Nullable Class<? extends View> princeClass, int princeBackgroundRes) {
                        Log.d("qw", "替换 " + viewName);
                        ShadowView shadowView = ShadowView.replaceOriginWithShadowView(context, princeAttrs, princeClass);
                        shadowView.setShadowSize(6, 0, 10, 12);
                        switch (princeBackgroundRes) {
                            case R.drawable.bg_btn_dangers:
                                shadowView.setStatusColors(getResources().getColor(R.color.R_5), getResources().getColor(R.color.R_2));
                                break;
                            case R.drawable.bg_btn_primary:
                                shadowView.setStatusColors(getResources().getColor(R.color.B_5), getResources().getColor(R.color.B_2));
                                break;
                            default:
                                break;
                        }
                        return shadowView;
                    }
                });
        //                new ViewReplaceHelper.Builder(this)
        //                        .orBackGround(R.drawable.bg_btn_dangers, R.drawable.bg_btn_primary)
        //                        .orStyle(R.style.btn_primary_just, R.style.btn_dangers_just)
        //                        .withTargetViewClass(TextView.class)
        //                        .build()
        //                        .replace(new ViewReplaceHelper.BaseCatConverter() {
        //                            @Override
        //                            public View onChangePrince(Context context, String princeName, AttributeSet princeAttrs, @Nullable Class<? extends View> princeClass, int princeStyleRes, int princeBackgroundRes) {
        //                                TextView textView = new TextView(context, princeAttrs);
        //                                Typeface typeface = Typeface.createFromAsset(getAssets(), "orange.ttf");
        //                                textView.setTypeface(typeface);
        //                                return textView;
        //                            }
        //                        });
        super.onCreate(savedInstanceState);

        setContentView(R.layout.demo_7_simples);
    }

    public void shadowChildView(View view) {
        Log.d("qw", findViewById(R.id.bt2).getClass().getSimpleName());
    }

}
